//
//  MBProgressHUD+MJ.m
//
//  Created by mj on 13-4-18.
//  Copyright (c) 2013年 itcast. All rights reserved.
//

#import "MBProgressHUD+HM.h"
#import "YLImageView.h"
#import "YLGIFImage.h"
@interface MBProgressHUD ()<UIWebViewDelegate>

@end
@implementation MBProgressHUD (HM)
#pragma mark 显示信息
+ (void)show:(NSString *)text icon:(NSString *)icon view:(UIView *)view
{
    if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
//    hud.labelText = text;
    hud.detailsLabelText=text;
    // 设置图片
    hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD.bundle/%@", icon]]];
    // 再设置模式
    hud.mode = MBProgressHUDModeText;
    
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    
    // 1秒之后再消失
    [hud hide:YES afterDelay:1.5];
    
    
}

#pragma mark 显示错误信息
+ (void)showError:(NSString *)error toView:(UIView *)view{
    [self show:error icon:@"error.png" view:view];
}

+ (void)showSuccess:(NSString *)success toView:(UIView *)view
{
    [self show:success icon:@"success.png" view:view];
}

#pragma mark 显示一些信息
+ (MBProgressHUD *)showMessage:(NSString *)message toView:(UIView *)view {
    
    if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:NO];
    hud.backgroundColor = [UIColor clearColor];
//    hud.labelText = message;
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    hud.isGB = YES;
    // YES代表需要蒙版效果
    hud.dimBackground = NO;
    hud.color = [UIColor blackColor];

    
//    UIView*alphaView = [[UIView alloc] initWithFrame:CGRectMake(0, SafeAreaTopHeight, SCREEN_HEIGHT-SafeAreaTopHeight, SCREEN_HEIGHT-SafeAreaTopHeight)];
//    alphaView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.4];
//
//    [hud addSubview:alphaView];
    
    
//    YLImageView*gifImageView = [[YLImageView alloc]initWithFrame:CGRectMake((SCREEN_WIDTH-60)/2, (SCREEN_HEIGHT-60)/2 , 60, 60)];
//    gifImageView.backgroundColor = [UIColor clearColor];
//    gifImageView.image = [YLGIFImage imageNamed:@"loadingAPP.gif"];
//    [hud addSubview:gifImageView];
    
    
    

    return hud;
}

+ (void)showSuccess:(NSString *)success
{
//    [self showSuccess:success toView:KWINDOW];
}

+ (void)showError:(NSString *)error
{
    [self showError:error toView:KWINDOW];
}

+ (MBProgressHUD *)showMessage:(NSString *)message
{
    return [self showMessage:message toView:nil];
}

+ (void)hideHUDForView:(UIView *)view
{
    [self hideHUDForView:view animated:NO];
}

+ (void)hideHUD
{
    [self hideHUDForView:nil];
}
@end
